import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
let defaultToken

try {
	const token = uni.getStorageSync('token')
	if (token) {
		defaultToken = token
	}
} catch (error) {

}
let hostL
let test = 'https://uplay-api.fiiwa.net/' //测试
let online = 'https://uplay-api.fiiwa.net/' //线上

if (process.env.NODE_ENV === 'development') { //development   production
	console.log('开发环境')
	hostL = test
} else {
	console.log('生产环境')
	hostL = online
}

const store = new Vuex.Store({
	state: {
		shanyanResult: null,
		imgRoot: 'http://u-play.oss-cn-beijing.aliyuncs.com/', //图片资源根地址
		baseUrl: hostL, //请求根地址
		token: defaultToken, //用户校验
		userInfo: uni.getStorageSync('userInfo')
	},
	mutations: {
		changeToken(state, data) {
			try {
				uni.setStorageSync('token', data)
			} catch (error) {}
			state.token = data
		},
		changeUserInfo(state, data) {
			try {
				uni.setStorageSync('userInfo', data)
			} catch (error) {}
			state.userInfo = data
		},
	}
})

export default store
